<?php
	function isXmlStructureValid($file) {
		$prev = libxml_use_internal_errors(true);
		$ret = true;
		try {
			new SimpleXMLElement($file);
		} catch(Exception $e) {
			$ret = false;
		}
		if(count(libxml_get_errors()) > 0) {
			$ret = false;
		}
		libxml_clear_errors();
		libxml_use_internal_errors($prev);
		return $ret;
	}
	require 'demo_voice/phone_credentials.php';
	$statusMessage='';
	$otherInfo='';
	if(isset($_POST['fname'])){
		$mobileNumber=preg_replace('/\D/','',$_POST['mobile']);
		require 'zipcodes.php';
		$city='.';
		if(isset($zipcodes[$_POST['zipcode']])){
			$city="I hope you had a good trip from ".$zipcodes[$_POST['zipcode']].". ".
				"And no, I'm not psychic. I simply looked up your city from your zipcode. ".
				"For even more impressive visual demos, visit us at extravagant. dot. i. o.".
				"And enjoy the rest of your Vegas trip ".$_POST['fname'].". Bye now.";
		}
		$data=array(
			'username'=>$smsMatrixUsername,
			'password'=>$smsMatrixPassword,
			'phone'=>$mobileNumber,
			'txt'=>'Hi '.$_POST['fname'].', thank you for trying our voice broadcast demo. '.$city,
		);
		$otherInfo=$data['phone']+'    '+$data['txt'];
		$curl=curl_init('http://www.smsmatrix.com/matrix_tts');
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		// If you experience SSL issues, perhaps due to an outdated SSL cert
		// on your own server, try uncommenting the line below
		// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
		$response=curl_exec($curl);
		curl_close($curl);
		$response=explode("\n",$response);
		foreach($response as $value){
			if(substr($value,0,11)=='STATUSCODE='){
				$statusMessage=explode("=",$value);
				$statusMessage=$statusMessage[1];
			}
		}
		if($statusMessage>399){
			$errors=array($statusMessage);
			$showPage=3; # errors
		}else{
			$showPage=2; # thank you page, demo submitted
		}
	}else{
		$showPage=1;
	}
	if($debugMode){
		$debugText='<pre>'.print_r($_POST,true).'</pre><pre>'.$statusMessage.'</pre><pre>'.$otherInfo.'</pre>';
	}else{
		$debugText='';
	}
	switch($showPage){
	case 3:
		echo "We have encountered some problems, please try again in a few minutes";
		echo $debugText;
		break;
	case 2:
		echo "Thank you for trying our demo, please allow up to 60 seconds for your demo to start";
		echo $debugText;
		break;
	case 1:
?><!DOCTYPE HTML>
<html lang="en">
	<head>
		<title>Extravagant.io - DEMO: Auto Voice</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link rel="icon" href="img/favicon.ico" type="image/x-icon">
		<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" />
		<meta name="description" content="Your description">
		<meta name="keywords" content="Your keywords">
		<meta name="author" content="Your name">
		<link rel="stylesheet" href="demo_voice/css/bootstrap.css" type="text/css" media="screen">
		<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
	<script type="text/javascript" src="js/include_script.js"></script>
		<!--[if lt IE 9]>
			<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
			<link href="css/ie.css" rel="stylesheet" type="text/css">
		<![endif]-->
	</head>
	<body>
		<!--content wrapper-->
		<div id="wrapper">
			<section>
				<div class="dynamicContent">
					<div class="row mar_b_6" id="competition_crushers_padding" style="background: url('img/splash_plane.png') repeat; margin-left: 0;">
						<div class="span5" id="demo_callme_button_style">
							<h2>Voice</h2>
							<p>
								The Call-Me button is a technological advancement that ties together websites with regular phone lines. The system works
								seamlessly on the webpage where it is placed. The user simply enters their # and is connected without any further action required.
								We’ve created a detailed diagram that outlines exactly how the system works.<br><br>

								The phone # input box has smart features integrated:<br>
								-Only numeric entry is allowed.<br>
								-The phone # must be 10 digits prior to initiating the call.<br>
								-Input numbers turn green when valid.<br><br>

								We can also ADD many Advanced Options: <br>
								-Pre-populate area code based on user’s IP address location (geo-location)<br>
								-Only accept valid US area codes<br>
								-Add a country dropdown and accept international numbers.<br>
								-The system has full support for international calling!<br>
							</p>
						</div>
						<div class="span6" id="demo_form_styles" >
							<h2 style="margin-left:10%;">The Demo</h2>
							<p class="p7"><br> 
								<span id="bgSpan">
									<div id="voiceDiv">
										<form id="voiceForm" method="post" onsubmit="return submitForm('#voiceForm')">
											<div class="padLeft"></div>
											<input id="fname" name="fname" placeholder="First name" type="text" value="" data-my-message="Please enter your first name" data-my-required="true" data-my-type="text">
											<div class="padRight"></div>
											<div class="padLeft"></div>
											<input id="mobile" name="mobile" placeholder="555-555-5555" type="tel" value="" data-my-message="Please enter a valid US mobile number" data-my-required="true" data-my-type="telUS"><br />
											<div class="padRight"></div>
											<div class="padLeft"></div>
											<input id="zipcode" maxlength="5" name="zipcode" placeholder="Zipcode" type="number" value="" data-my-message="Please enter a valid US zip code" data-my-required="false" data-my-type="zipcodeUS"><br />
											<div class="padRight"></div>
											<input id="buttonSubmit" value="Start Demo" name="voice" type="submit">
										</form> 
									</div>
								</span>
								<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
							</p>
						</div> 
					</div>
					<div class="bord3"></div>
				</div>
			</section>
		</div>
		<script type="text/javascript" src="js/bootstrap.js"></script>
		<script type="text/javascript"><!--
			var phone_script=document.createElement('link');
			phone_script.rel="stylesheet";
			phone_script.type="text/css";
			phone_script.href="demo_voice/css/jquery-bubble-popup-v3.css";
			document.getElementsByTagName('head')[0].appendChild(phone_script);
			phone_script=document.createElement('link');
			phone_script.rel="stylesheet";
			phone_script.type="text/css";
			phone_script.href="demo_voice/css/phone.css";
			document.getElementsByTagName('head')[0].appendChild(phone_script);
			phone_script=document.createElement('script');
			phone_script.src="demo_voice/js/jquery-bubble-popup-v3.min.js";
			phone_script.type="text/javascript";
			document.getElementsByTagName('head')[0].appendChild(phone_script);
			phone_script=document.createElement('script');
			phone_script.src="demo_voice/js/phone.js";
			phone_script.type="text/javascript";
			document.getElementsByTagName('head')[0].appendChild(phone_script);
		//--></script>
	</body>
</html>
<?php
		break;
	}
?>
